#include <iostream>
#include <queue>
#include <string>
using namespace std;
struct TreeNode;
void Creat_TreeNode_right(string::iterator& it, TreeNode* root);

struct TreeNode {
    TreeNode(int val)
        : _val(val) {}

    ~TreeNode() {
        queue<TreeNode*> qt;
        qt.push(this);
        while (qt.empty()) {
            if (qt.front()->_left)
                qt.push(qt.front()->_left);
            if (qt.front()->_right)
                qt.push(qt.front()->_right);
            free(qt.front());
            qt.pop();
        }
        _left = _right = nullptr;
    }

    char _val;
    TreeNode* _left;
    TreeNode* _right;
};

void Creat_TreeNode_left(string::iterator& it, TreeNode* root) {
    if (*it == '#') {
        it++;
        return;
    }
    auto Node = new TreeNode(*it++);
    root->_left = Node;
    Creat_TreeNode_left(it, root->_left);
    Creat_TreeNode_right(it, root->_left);
}

void Creat_TreeNode_right(string::iterator& it, TreeNode* root) {
    if (*it == '#') {
        it++;
        return;
    }
    auto Node = new TreeNode(*it++);
    root->_right = Node;
    Creat_TreeNode_left(it, root->_right);
    Creat_TreeNode_right(it, root->_right);
}


void Creat_TreeNode(string::iterator& it, TreeNode* root) {
    Creat_TreeNode_left(it, root);
    Creat_TreeNode_right(it, root);
}

void InOrder(TreeNode* root) {
    if(root == nullptr)
        return;
    InOrder(root->_left);
    cout << root->_val << " ";
    InOrder(root->_right);
}

int main() {
    string str;
    while (getline(cin, str)) {
        auto it = str.begin();
        auto head = new TreeNode(*it++);
        Creat_TreeNode(it, head);
        InOrder(head);
        cout << endl;
    }
}